package com.yyfax.ph.progress.checkCredit;

import com.yyfax.infrastructure.eventbus.EventAgent;
import com.yyfax.infrastructure.mvp.Model;
import com.yyfax.infrastructure.network.NetworkHelper;
import com.yyfax.infrastructure.network.entity.BaseResultEntity;
import com.yyfax.ph.base.YJPH;
import retrofit2.http.Body;
import retrofit2.http.Header;
import retrofit2.http.POST;
import rx.Observable;

import java.util.List;

public class CheckCreditModel extends Model {
	private static final String TAG = CheckCreditModel.class.getSimpleName();

	@Override
	public void onNext(Object obj) {
		CreditResult detailResult = cast(obj);
		EventAgent.post(detailResult);
	}

	@Override
	public Observable getObservable(Object params, int functionalCode) {
		Service service = (Service) NetworkHelper.createService(Service.class);
		String token = YJPH.getInstance().getPreferenceManager().getLoginToken();
		return service.getDetailCredit(token, (Params) params);
	}

	private interface Service {
		@POST("apply/query/getDetailCredit")
		Observable<CreditResult> getDetailCredit(@Header("token") String token, @Body Params params);
	}


	public static class Params {
		/**
		 * 推荐编号
		 */
		public String rcmdId = "";
	}

	public static class CreditResult extends BaseResultEntity<List<Credit>> {
	}


	protected static class Credit {
		/**  */
		public String url = "";
		public String type = "";

		@Override
		public String toString() {
			final StringBuffer sb = new StringBuffer("Hot{");
			sb.append("id='").append(url).append('\'');
			sb.append(", type='").append(type).append('\'');
			sb.append('}');
			return sb.toString();
		}
	}

}
